﻿@{
    Layout = "~/Views/Shared/_AdminLayout.cshtml";
}
@section styles{
}
<div id="app" class="box box-primary">
    <div>
        <el-row type="flex" justify="center">
            <el-col v-bind:span="9">
                <h3 class="text-center text-danger title">分销单</h3>
            </el-col>
        </el-row>
        <el-row>
            <el-col v-bind:span="8">单号：{{model.Code}}</el-col>
            <el-col v-bind:span="8">办卡人微信昵称：{{model.NickName}}</el-col>
            <el-col v-bind:span="8">办卡电话：{{model.MemberPhone}}</el-col>
        </el-row>
        <el-row>
            <el-col v-bind:span="8">办卡人身份证：{{model.IdentityCard}}</el-col>            
            <el-col v-bind:span="8">办卡人：{{model.MemberName}}</el-col>
            <el-col v-bind:span="8">办卡人联系电话：{{model.ContactPhone}}</el-col>
        </el-row>
        <el-row>
            <el-col v-bind:span="8">销售单号：{{model.SaleOrderCode}}</el-col>
            <el-col v-bind:span="8">推荐人：{{model.ReferMemberName}}</el-col>
            <el-col v-bind:span="8">推荐人电话：{{model.ReferPhone}}</el-col>
        </el-row>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>会员ID</th>
                    <th>微信昵称</th>
                    <th>真实名称</th>
                    <th>开卡电话</th>
                    <th>联系电话</th>
                    <th>返利等级</th>
                    <th>返利金额</th>
                    <th>提现状态</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(item,index) in model.Items">
                    <td>{{index+1}}</td>
                    <td>{{item.MemberId}}</td>
                    <td>{{item.NickName}}</td>
                    <td>{{item.RealName}}</td>
                    <td>{{item.Phone}}</td>
                    <td>{{item.SecondPhone}}</td>
                    <td>{{item.ProfitLevel}}</td>
                    <td>{{item.ProfitAmount}}</td>
                    <td>{{item.CashStatusName}}</td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <td></td>
                    <td>合计：</td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td></td>
                    <td class="text-danger">{{model.TotalAmount}}</td>
                    <td><el-button type="success" v-on:click="paidByFinance(model)" title="全部标记已付款" v-if="model.ShowFinance">一键打款</el-button></td>
                </tr>
            </tfoot>
        </table>
        <el-row>
            <el-col v-bind:span="8">
                <span>
                    单据状态：
                    <el-tag v-if="model.Status==-1" type="danger">{{model.StatusName}}</el-tag>
                    <el-tag v-else type="success">{{model.StatusName}}</el-tag>
                </span>
            </el-col>
            <el-col v-bind:span="8">制单时间：{{model.CreatedOnTime}}</el-col>
            <el-col v-bind:span="8">
                <el-input v-model="form.remark" ref="remark" type="text" placeholder="审核备注" maxlength="50" show-word-limit="true" clearable> </el-input>
            </el-col>
        </el-row>
    </div>
    <div>
        <h4>单据处理记录：</h4>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>序号</th>
                    <th>当前状态</th>
                    <th>处理人</th>
                    <th>处理时间</th>
                    <th>操作说明</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="(item,index) in model.Historys">
                    <td>{{index+1}}</td>
                    <td>{{item.StatusName}}</td>
                    <td>{{item.CreatedbyName}}</td>
                    <td>{{item.CreatedOn}}</td>
                    <td>
                        <el-tag v-if="item.Status==-1" type="danger">{{item.Remark}}</el-tag>
                        <el-tag v-else type="success">{{item.Remark}}</el-tag>

                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
@section scripts{
    <script type="text/javascript">
        var demo = new Vue({
            el: '#app',
            data: {
                lock: false,
                model: @Html.Raw(ViewBag.Order),
                form: {
                    id: 0,
                    phone:'',
                    remark:'',
                }
            },
            methods: {
                //审核驳回
                auditPhone: function (dialog, button,callback) {
                    var $this = this;
                    this.form.id = this.model.Id;
                    var data =this.form;
                    if (this.form.remark == "")
                    {
                        this.$message.error('审核意见不能为空');
                        button.unlock();
                        this.$refs['remark'].focus();
                        return;
                    }
                    $.ajax({
                        type: 'post',
                        url: "/DistributeOrder/AuditPhone",
                        data: JSON.stringify(data),
                        dataType: "json",
                        contentType: 'application/json',
                        success: function (result) {
                            if (result.success) {
                                $this.$message.success({
                                    message:"审核成功！",
                                    onClose:function(){
                                        button.unlock();
                                        dialog.close();
                                        if(callback)
                                        {
                                            callback();
                                        }
                                    }
                                });
                            }else {
                                button.unlock();
                                $this.$message.error(result.error);
                            }
                        }
                    });
                },
                //确认提现
                confirmCash: function (dialog, button, callback) {
                    var $this = this;
                    this.form.id = this.model.Id;
                    var data = this.form;
                    if (this.form.remark == "")
                    {
                        this.$message.error('审核意见不能为空');
                        button.unlock();
                        this.$refs['remark'].focus();
                        return;
                    }
                    $.ajax({
                        type: 'post',
                        url: "/DistributeOrder/ConfirmCash",
                        data: JSON.stringify(data),
                        dataType: "json",
                        contentType: 'application/json',
                        success: function (result) {
                            if (result.success) {
                                $this.$message.success({
                                    message:"操作成功！",
                                    onClose:function(){
                                        button.unlock();
                                        dialog.close();
                                        if(callback)
                                        {
                                            callback();
                                        }
                                    }
                                });
                            }else {
                                button.unlock();
                                $this.$message.error(result.error);
                            }
                        }
                    });
                },
                //取消
                cancel:function(dialog, button, callback){
                    dialog.close();
                },
                 dateCellFormatter: function (row, column, cellValue, index) {
                    return cellValue.toDate().format("yyyy-MM-dd hh:mm");
                },
                paidByFinance: function (model) {
                    var $this = this;
                    this.$confirm('此操作将标记已打款给客户, 是否继续?', '系统提示', {
                        confirmButtonText: '确定',
                        cancelButtonText: '取消',
                        type: 'warning'
                    }).then(() => {
                        var data = { id: model.Id };
                        $.ajax({
                            type: 'post',
                            url: "/DistributeOrder/PaidByFinance",
                            data: JSON.stringify(data),
                            dataType: "json",
                            contentType: 'application/json',
                            success: function (result) {
                                if (result.success) {
                                    $this.$message.success({
                                        message: "操作成功！"
                                    });
                                } else {
                                    $this.$message.error(result.error);
                                }
                            }
                        });


                    }).catch(() => {
                        
                    });
                   
                }
            },
            computed:{

            },
            created:function(){
                var dialog = window.parent.activeDialog;
                if (dialog) {
                dialog.bindEvent("auditPhone",this.auditPhone);
                dialog.bindEvent("confirmCash",this.confirmCash);
                //dialog.bindEvent("abandonSaleOrder",this.abandonSaleOrder);
                dialog.bindEvent("cancel",this.cancel);
                // this.addRow();
                }
            }
        });
    </script>
}
